/**
 * fixTableHeight
 * 动态根据页面高度设置table的高度
 */
export default {
  mounted(el: any, binding: any) {
    el.windowChange = () => {
      const bottomHeight = binding?.value || 0
      el.timer && clearTimeout(el.timer)
      el.timer = setTimeout(() => {
        el.style.transition = 'height 0.3s'
        el.style.height = `${window.innerHeight - el.getBoundingClientRect().top - 100 - bottomHeight}px`
        setTimeout(() => {
          el.style.transition = ''
        }, 0)
      }, 0)
    }
    el.windowChange()
    window.addEventListener('resize', el.windowChange)
  },
  beforeUnmount(el: any) {
    window.removeEventListener('resize', el.windowChange)
    clearTimeout(el.timer)
    delete el.timer
    delete el.windowChange
  }
}
